package com.tongda.menu.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tongda.core.vo.TableArea;
import com.tongda.menu.R;
import com.tongda.menu.R.drawable;

public class TableAreaAdapter extends BaseAdapter{
	private List<TableArea> datas;
	private Context context;
	private int currentPosition = 0;
	
	
	public TableAreaAdapter(List<TableArea> datas, Context context) {
		super();
		this.datas = datas;
		this.context = context;
	}
	@Override
	public int getCount() {
		return datas.size();
	}
	@Override
	public Object getItem(int position) {
		return datas.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if(convertView==null){
			holder = new Holder();
			convertView = View.inflate(context, R.layout.adapter_item_tablearea, null);
			holder.dsbg = (LinearLayout)convertView.findViewById(R.id.adapter_item_tbbg);
			holder.dsReplaceTv = (TextView)convertView.findViewById(R.id.adapter_item_areaTv);
			holder.dsReplaceTv.setTextColor(Color.BLACK);
			holder.dsReplaceTv.setTextSize(20);
			holder.dsReplaceTv.setGravity(Gravity.CENTER);
			convertView.setTag(holder);
		}else{
			holder = (Holder) convertView.getTag();
		}
		
		if(currentPosition==position){
			holder.dsbg.setBackgroundResource(drawable.selected_bg);
		}else{
			holder.dsbg.setBackgroundResource(drawable.unselected_bg);
		}
		
		holder.dsReplaceTv.setText(datas.get(position).getName());
		
		return convertView;
	}
	
	public class Holder{
		LinearLayout dsbg;
		TextView dsReplaceTv;
	}


	public int getCurrentPosition() {
		return currentPosition;
	}
	public void setCurrentPosition(int currentPosition) {
		this.currentPosition = currentPosition;
	}
}
